<?php

namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\Config;

class UserResource extends JsonResource
{
    public function toArray($request)
    {
	    $resource = $this->resource;
	    $config = Config::find(1);
        $data = [
	        'id' => (int)$resource->id,
		    'parent_id' => (int)$resource->parent_id,

		    'balance' =>  (int)$resource->balance,
		    'address' =>  $resource->address,

	        'grade' => (string)$resource->grade,
		    'invite_code' => (string)$resource->invite_code,
		    'province_code' => (string)$resource->province_code,
		    'city_code' => (string)$resource->city_code,
		    'province' => (string)$resource->province,
		    'city' => (string)$resource->city,
	        'invite_string' => $resource->inviteString(),

	        'name' => $resource->name ?? '',
	        'nickname' => $resource->nickname ?? '',
	        'phone' => $resource->phone ?? '',
	        'signature' => $resource->signature ?? '',
	        'avatar_url' => img_path($resource->avatar),
	        'gender' => $resource->gender ?? '',
	        'birthday' => $resource->birthday ?? '',

	        'dividend_all' => $resource->dividend_all,
	        'dividend_day' => $resource->dividend_day,

	        'is_phone_bound' => $resource->isPhoneBound(),
	        'is_weixin_bound' => $resource->isWeixinBound(),
	        'is_weimini_bound' => $resource->isWeiminiBound(),
	        'is_alipay_bound' => $resource->isAlipayBound(),

	        'wx_nickname' => $resource->wx_nickname ?? '',
	        'wx_headimgurl' => $resource->wx_headimgurl ?? '',
	        'alipay_nickname' => $resource->alipay_nickname ?? '',
	        'alipay_avatar' => $resource->alipay_avatar ?? '',
	        'alipay_user_no' => $resource->alipay_user_no ?? '',

	        'parent_phone' => $resource->parent_phone,
	        'parent_name' => $resource->parent_name,
	        'parent_avatar_url' => img_path($resource->parent_avatar),

	        'created_at' => (string)$resource->created_at,
	        'vip_expired_at' => (string)$resource->vip_expired_at,
	        'shop_name'=>$config->name,
	        'yysj' => $config->yysj,
	        'shop_phone' => $config->phone,
	        'shop_desc' => $config->desc,
	        'shop_address' => $config->address,
	        'shop_image' => $config->image,
	        'yyjf' => $resource->rewards()->sum("money"), 

        ];

        return $data;
    }
}
